<?php
/**
 * Created by PhpStorm.
 * User: ship
 * Date: 2024/12/26
 * Time: 13:04
 */

namespace ShipSun\LaravelSignature;

use Illuminate\Support\ServiceProvider;

/**
 * Class LaravelSignatureProvider
 * @package ShipSun\LaravelSignature
 */
class LaravelSignatureProvider extends ServiceProvider
{
    public function register()
    {
        $this->mergeConfigFrom(__DIR__ . '/../config/signature.php', 'signature');
        $config = config('signature', []);
        SignatureMiddleware::$sign_key = $config['sign_key'] ?? '123456';
        SignatureMiddleware::$enable = $config['enable'] ?? false;
        SignatureMiddleware::$close_path = $config['close_path'] ?? false;
        $this->app->singleton(Signature::class, function ($app) {
            return new Signature($app);
        });
        $this->app->singleton(SigningStr::class, function ($app) {
            $param = $app->config->get('signature.param');
            return new SigningStr($param);
        });
        $this->publishes([__DIR__ . '/../config/signature.php' => $this->app->configPath('signature.php')], ['signature']);
    }
}